home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / misc / NVX_timeul2.lha / C_Source.lha / GadToolsStart.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  8KB  |  323 lines

  1. ;/* GadToolsStart - Execute me to compile me with Lattice.
  2. LC -b0 -cfistq -v -y GadToolsStart.c
  3. Blink with Make
  4. quit
  5. */
  6.  
  7.  
  8.     /* ****************************************************** */
  9.     /*                     Include Commodore files                  */
  10.     /* ****************************************************** */
  11.  
  12. #include "stdio.h"
  13.  
  14. #include <exec/exec.h>
  15. #include <intuition/intuition.h>
  16. #include <intuition/screens.h>
  17. #include <intuition/classes.h>
  18. #include <intuition/classusr.h>
  19. #include <intuition/gadgetclass.h>
  20. #include <graphics/displayinfo.h>
  21. #include <libraries/dos.h>
  22. #include <libraries/asl.h>
  23. #include <libraries/gadtools.h>
  24. #include <utility/tagitem.h>
  25. #include <workbench/startup.h>
  26. #include <workbench/workbench.h>
  27.  
  28. #include <proto/exec.h>
  29. #include <proto/intuition.h>
  30. #include <proto/dos.h>
  31. #include <proto/graphics.h>
  32. #include <proto/asl.h>
  33. #include <proto/gadtools.h>
  34. #include <proto/utility.h>
  35. #include <proto/icon.h>
  36.  
  37. #ifdef LATTICE
  38. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  39. int chkabort(void) { return(0); }  /* really */
  40. #endif
  41.  
  42.     /* ****************************************************** */
  43.     /*                     Include other files                      */
  44.     /* ****************************************************** */
  45.  
  46.  
  47.     /* ****************************************************** */
  48.     /*                         Declarations                      */
  49.     /* ****************************************************** */
  50.  
  51.  
  52.     /* ****************************************************** */
  53.     /*                     Function Prototypes                      */
  54.     /* ****************************************************** */
  55.  
  56. BOOL open_libs( void );
  57. void close_libs( void );
  58.  
  59. /* The following routines are made global so all code can access them */
  60.  
  61. extern void OkReq( char *title);
  62. extern BOOL TFReq( char *title);
  63. void ClearList( struct List *);
  64. void DoTools( char *name );
  65.  
  66.     /* ****************************************************** */
  67.     /*                 External Function Prototypes              */
  68.     /* ****************************************************** */
  69.  
  70. #include "gui.h"
  71.  
  72.     /* ****************************************************** */
  73.     /*                 Global variable declerations              */
  74.     /* ****************************************************** */
  75.  
  76. struct IntuitionBase *IntuitionBase=NULL;
  77. struct GfxBase *GfxBase=NULL;
  78. extern struct DOSBase *DOSBase;
  79. struct AslBase *AslBase=NULL;
  80. struct GadToolsBase *GadToolsBase=NULL;
  81. struct UtilityBase *UtilityBase=NULL;
  82. struct Library *AmigaGuideBase=NULL;
  83.  
  84. struct Window *win;
  85. struct IntuiMessage *msg;
  86. USHORT msg_code;
  87. struct Gadget *gadg;
  88.  
  89. struct List *SelFiles=NULL;
  90. struct FileRequester *OurFReq;        /* For File Selection */
  91. LONG TotalK=0, Rate=30;
  92. LONG Rates[] = { 30, 120, 240, 480, 960, 1440, 1680, 1920, 2160, 2880 };
  93.  
  94. UWORD index=0;
  95. char ptrn[50]="(*.lha|*.lzx|*.dms)";
  96.  
  97.     /* ****************************************************** */
  98.     /*                         Main                              */
  99.     /* ****************************************************** */
  100.  
  101. void _main( int argc, char *argv[] )
  102. {
  103.  
  104. int m;
  105. struct WBStartup *WBmsg;
  106. struct WBArg *WBarg;
  107. BPTR parent_dir=NULL;
  108.  
  109. if( open_libs() )
  110.     {
  111.  
  112.     /* CD to our directory if from Workbench */
  113.  
  114.     if (argc == 0)                            /* Only 0 when from Workbench */
  115.         {
  116.         WBmsg=(struct WBStartup *)argv;        /* argv -> WBStartup message */
  117.         WBarg=WBmsg->sm_ArgList;            /* 1st WB Argumeent */
  118.         if ( WBarg->wa_Lock ) parent_dir=(BPTR)CurrentDir(WBarg->wa_Lock );
  119.         DoTools( WBarg->wa_Name );            /* Examine icons ToolTypes */
  120.         }
  121.     else
  122.         DoTools( "TimeUL" );
  123.  
  124.     /* Get a file requester */
  125.     if( OurFReq=(struct FileRequester *)
  126.         AllocAslRequestTags( ASL_FileRequest,
  127.                             ASLFR_TitleText, "Select Files .... ", TAG_DONE ) )
  128.         {
  129.  
  130.         if( !SetupScreen() )
  131.             {
  132.             if ( !OpenMarksWindow() )
  133.                 {
  134.  
  135.                 /* Set default rate & CPS */
  136.                 Rate = Rates[index];
  137.                 GT_SetGadgetAttrs( MarksGadgets[1], MarksWnd, NULL, GTMX_Active, index, TAG_END );
  138.                 GT_SetGadgetAttrs( MarksGadgets[8], MarksWnd, NULL, GTNM_Number, Rate, TAG_END );
  139.  
  140.                 m=1;
  141.                 while (m) m=HandleMarksIDCMP();
  142.                 CloseMarksWindow();
  143.                 }
  144.             CloseDownScreen();
  145.             }
  146.         /* Free the file requester structure */
  147.         FreeAslRequest( OurFReq );
  148.         }
  149.     if ( parent_dir ) CurrentDir( parent_dir );
  150.     }
  151. close_libs();
  152.  
  153. }
  154.  
  155.     /* ****************************************************** */
  156.     /*             Attempt to open required libraries               */
  157.     /* ****************************************************** */
  158.  
  159. /* ASL library is attempted, but if not there the program will continue */
  160.  
  161. BOOL open_libs( void )
  162. {
  163.  
  164. BOOL ok=FALSE;
  165.  
  166. if ( IntuitionBase = (struct IntuitionBase *)
  167.          OpenLibrary ( "intuition.library",0) )
  168.     
  169.     if ( GfxBase = (struct GfxBase *)
  170.            OpenLibrary( "graphics.library",0) )
  171.  
  172.     if ( GadToolsBase = (struct GadToolsBase *)
  173.            OpenLibrary( "gadtools.library", 0L ) )
  174.  
  175.     if ( UtilityBase = (struct UtilityBase *)
  176.            OpenLibrary( "utility.library", 0L ) )
  177.  
  178.     if ( AslBase = (struct AslBase *)
  179.            OpenLibrary( AslName, 0 ) )
  180.  
  181.     if ( SelFiles=(struct List *)AllocMem( sizeof(struct List),MEMF_CLEAR) )
  182.             {
  183.             NewList( SelFiles );
  184.             ok=TRUE;
  185.             }
  186.  
  187. AmigaGuideBase = (struct Library *) OpenLibrary( "amigaguide.library", 0 );
  188.  
  189. return ok;
  190. }
  191.  
  192.     /* ****************************************************** */
  193.     /*                     Close Any Open Libraries              */
  194.     /* ****************************************************** */
  195.  
  196. void close_libs( void )
  197. {
  198. if ( IntuitionBase ) CloseLibrary( (struct Library *)IntuitionBase );
  199. if ( GfxBase ) CloseLibrary( (struct Library *)GfxBase );
  200. if ( AslBase ) CloseLibrary( (struct Library *)AslBase );
  201. if ( GadToolsBase ) CloseLibrary( (struct Library *)GadToolsBase );
  202. if ( UtilityBase ) CloseLibrary( (struct Library *)UtilityBase );
  203. if ( AmigaGuideBase ) CloseLibrary( AmigaGuideBase );
  204.  
  205. if ( SelFiles )
  206.     {
  207.     ClearList( SelFiles );
  208.     FreeMem( SelFiles, sizeof(struct List) );
  209.     }
  210. }
  211.  
  212.     /* ****************************************************** */
  213.     /*                     A Simple OK Requester                  */
  214.     /* ****************************************************** */
  215.  
  216. void OkReq( char *title )
  217. {
  218.  
  219. struct EasyStruct easy =
  220.     {
  221.     sizeof( struct EasyStruct ),
  222.     NULL,
  223.     NULL,
  224.     NULL,
  225.     "Ok"
  226.     };
  227.  
  228. easy.es_TextFormat = title;
  229. EasyRequest( MarksWnd, &easy, NULL, 0L );
  230.  
  231. }
  232.  
  233.     /* ****************************************************** */
  234.     /*                     An Ok--Cancel Requester                  */
  235.     /* ****************************************************** */
  236.  
  237. BOOL TFReq( char *title )
  238. {
  239.  
  240. BOOL RetVal;
  241. struct EasyStruct easy =
  242.     {
  243.     sizeof( struct EasyStruct ),
  244.     NULL,
  245.     NULL,
  246.     NULL,
  247.     "Cancel|Ok"
  248.     };
  249.  
  250. easy.es_TextFormat = title;
  251. RetVal=(BOOL)EasyRequest( MarksWnd, &easy, NULL, 0L );
  252.  
  253. return RetVal;
  254.  
  255. }
  256.  
  257.     /* ****************************************************** */
  258.     /*                     Examine Tool Types                      */
  259.     /* ****************************************************** */
  260.  
  261. /* given name of program, examine it's icons ToolTypes. Assumes we are in */
  262. /* the same directory as the program, cd to it if from WBench.              */
  263.  
  264. void DoTools( char *name )
  265. {
  266.  
  267. struct Library *IconBase;
  268. struct DiskObject *object;
  269. char **toolsarray,*s;
  270.  
  271. if( IconBase=(struct Library *)OpenLibrary( "icon.library", 0L ) )
  272.     {
  273.         
  274.     /* Can now load in our icon */
  275.     if ( object=GetDiskObject( name ) )
  276.         {
  277.         toolsarray=(char **)object->do_ToolTypes;
  278.                 
  279.         if( s=(char *)FindToolType( toolsarray, "300" ))
  280.             Rates[0]=atol( s );
  281.         
  282.         if( s=(char *)FindToolType( toolsarray, "1200" ))
  283.             Rates[1]=atol( s );
  284.         
  285.         if( s=(char *)FindToolType( toolsarray, "2400" ))
  286.             Rates[2]=atol( s );
  287.         
  288.         if( s=(char *)FindToolType( toolsarray, "4800" ))
  289.             Rates[3]=atol( s );
  290.         
  291.         if( s=(char *)FindToolType( toolsarray, "9600" ))
  292.             Rates[4]=atol( s );
  293.         
  294.         if( s=(char *)FindToolType( toolsarray, "14400" ))
  295.             Rates[5]=atol( s );
  296.         
  297.         if( s=(char *)FindToolType( toolsarray, "16800" ))
  298.             Rates[6]=atol( s );
  299.         
  300.         if( s=(char *)FindToolType( toolsarray, "19200" ))
  301.             Rates[7]=atol( s );
  302.         
  303.         if( s=(char *)FindToolType( toolsarray, "21600" ))
  304.             Rates[8]=atol( s );
  305.         
  306.         if( s=(char *)FindToolType( toolsarray, "28800" ))
  307.             Rates[9]=atol( s );
  308.  
  309.         if( s=(char *)FindToolType( toolsarray, "DEFRATE" ))
  310.             {
  311.             index=atol( s );
  312.             if( index<0 || index>9 )index=0;
  313.             }
  314.  
  315.         if( s=(char *)FindToolType( toolsarray, "PATTERN" ))
  316.             strcpy( ptrn, s );
  317.  
  318.         FreeDiskObject( object );
  319.         }
  320.     CloseLibrary( IconBase );
  321.     }
  322. }
  323.